<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    div{
        width: 600px;
        height: 700px;
    }

</style>


<body>
    <div>
        <img src="./img/1.png" style="width:600px;height:700px">
    </div>
    <script>
        //HTMLcollection数组
        var img = document.getElementsByTagName('img')[0];
        const imgArr = ['1.png','2.png','3.png','4.png'];
        var count = 0;

        //只执行一次
        function fn() {
            if (count < 3) {
                count++;
            }else{
                count = 0;
            }
            img.src = './img/' + imgArr[count];
            return setTimeout(fn,3000);

        }
        setTimeout(fn,3000);
    </script>
</body>
</html>